package com.yuba.front.controller.collect;

import com.yuba.common.core.constant.ActionTypes;
import com.yuba.common.core.domain.R;
import com.yuba.common.core.validate.ActionCollectFishGroup;
import com.yuba.common.core.validate.ActionCollectPostGroup;
import com.yuba.common.satoken.utils.LoginHelper;
import com.yuba.common.web.core.BaseController;
import com.yuba.front.domain.param.ActionParam;
import com.yuba.front.service.ICollectFishSiteService;
import com.yuba.front.service.ICollectPostsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收藏接口
 *
 * @author modakai
 */
@RestController
@RequestMapping("/api/collect")
@RequiredArgsConstructor
public class ApiCollectController extends BaseController {

    private final ICollectPostsService collectPostsService;
    private final ICollectFishSiteService fishSiteService;

    /**
     * 收藏/取消收藏帖子
     *
     * @param body 请求参数
     * @return 无
     */
    @PostMapping("posts")
    public R<Void> collectPosts(@RequestBody @Validated(ActionCollectPostGroup.class) ActionParam body) {
        String type = body.getType();
        if (ActionTypes.COLLECT.equals(type)) {
            collectPostsService.collectPosts(body.getPostsId(), LoginHelper.getUserId(), body.getAuthorId());
        } else {
            collectPostsService.unCollectPosts(body.getPostsId(), body.getAuthorId(), LoginHelper.getUserId());
        }

        return R.ok();
    }

    /**
     * 收藏or取消收藏钓点
     * @param body 请求参数
     * @return 无
     */
    @PostMapping("fishSite")
    public R<Void> collectFishSite(@RequestBody @Validated({ActionCollectFishGroup.class}) ActionParam body) {
        fishSiteService.collectFishSite(body,LoginHelper.getUserId());
        return R.ok();
    }
}
